package com.bridgeintelligent.tag.webserver.dim.mgmt.service.index;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.BaseCode;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimException;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.CustomersDownloadVO;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.IndexDimCatalogVO;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.IndexMonitorVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @description
 * @author: grp 2021-01-06 10:27
 **/
@Api(tags = "首页相关接口")
@RestController
@RequestMapping("/api/index")
@AllArgsConstructor
public class IndexController {

    private IndexService indexService;

    @ApiOperation(value = "首页一级目录标签数接口")
    @GetMapping("/dimCatalog")
    public DimRep<List<IndexDimCatalogVO>> dimCatalog() {
        try {
            List<IndexDimCatalogVO> list = indexService.dimCatalog();
            return new DimRep<>(list, BaseCode.SUCCESS);
        } catch (DimException e) {
            return new DimRep<>(null,e.getCode(), "操作失败");
        }
    }

    @ApiOperation(value = "首页一级目录标签的使用次数接口")
    @GetMapping("/dimUseNum")
    public DimRep<Map<String, List<IndexDimCatalogVO>>> dimUseNum() {
        try {
            Map<String, List<IndexDimCatalogVO>> map = indexService.dimUseNum();
            return new DimRep<>(map, BaseCode.SUCCESS);
        } catch (DimException e) {
            return new DimRep<>(null, e.getCode(), "操作失败");
        }
    }

    @ApiOperation(value = "首页一级目录标签的使用次数接口")
    @GetMapping("/customersDownloadNum")
    public DimRep<List<CustomersDownloadVO>> customersDownloadNum() {
        try {
            List<CustomersDownloadVO> result = indexService.customersDownloadNum();
            return new DimRep<>(result, BaseCode.SUCCESS);
        } catch (DimException e) {
            return new DimRep<>(null, e.getCode(), "操作失败");
        }
    }

    @ApiOperation(value = "首页整体指标查询接口")
    @GetMapping("/base")
    public DimRep base(){
        try {
            Map<String,IndexMonitorVO> result = indexService.monitorNum();
            return new DimRep<>(result, BaseCode.SUCCESS);
        } catch (DimException e) {
            return new DimRep<>(null, e.getCode(), "操作失败");
        }
    }
}
